<?php
  $path = drupal_get_path('module', 'government');
  drupal_add_css($path . '/css/government.css');


function governmentshome() {
global $base_url;
$url = $base_url . '/' . drupal_get_path('module', 'government');

//print $base_url;
drupal_set_title(t('About Tamil Nadu'));

//$governor = "node/197";//"node/173";

$governor="$base_url/government/keycontact/197";  
//$governor="honble-governor-tamil-nadu"; C
//$CM = "node/18347"; //"node/172     196";
//$CM = "honble-chief-minister-tamil-nadu";

$CM="$base_url/government/keycontact/18358";
//$CJ = "node/198"; //"node/174";

$CJ="$base_url/government/keycontact/198";

//to get state profile
/**vid is checked in query by suba on aug10th**/
my_db_change(1);

//$sql_state = db_query("select n.nid,n.title,p.field_tn_capital_value,p.field_tn_population_value,p.field_tn_administrative_units_value from {content_type_profile_state} as p,{node} as n where n.nid=p.nid and n.vid = p.vid order by p.nid desc LIMIT 1");

$sql_state = db_query("select nid,title,field_tn_administrative_units_value,field_tn_population_value FROM 
                       node n,field_data_field_tn_administrative_units fav,field_data_field_tn_population pov
					   where n.type='profile_state' and fav.entity_id=n.nid and fav.bundle=n.type and n.vid= fav.revision_id 
					   AND n.type='profile_state' and pov.entity_id=n.nid and pov.bundle=n.type and n.vid= pov.revision_id 
					   ORDER BY n.nid DESC LIMIT 1 ");

my_db_change(0);
//$statedata = db_fetch_object($sql_state);
while($statedata = $sql_state->fetchAssoc())
{
$strData = '
<div class="contentarial_grey" >
<p align="center" class="style2head">
   About Tamil Nadu </p>
   
<p align="center" class="style3head">
   <a target="_blank" href="'.$url.'/files/tamilthaivazhthusong.pdf">'.SITE_LANG.' Invocation Song </a>
   <a target="_blank" href="'.$url.'/files/thamizhthaivazhthu.mp3"><img src= "'.$url.'/images/Audio-Icon.png" height="15" width="15" /></a></p>
   
  <p><span class="cm_link">His Excellency the Governor of '.SITE_STATE.' <a class="submenu_selected" href="'.$governor.'">Thiru K Rosaiah</a> is the constitutional Head of the State.</span> <br>
  
   <div class="cm_link">
    Hon\'ble Chief Minister of '.SITE_STATE.' <a class="submenu_selected" href="'.$CM.'"> Selvi J Jayalalithaa</a> is the Head of the elected Government and heads the Council of Ministers.</div>
    <br><div  class="cm_link">
    Hon\'ble Acting Chief Justice of Madras High Court <a class="submenu_selected" href="'.$CJ.'"> Thiru. Justice Rajesh Kumar Agrawal</a> is the Head&nbsp; of Judiciary.&nbsp;</div><br>
    <div  class="cm_link"> '.SITE_STATE.' State has a population of '.$statedata['field_tn_population_value'].' as per 
	<a class="submenu_selected" href="http://www.census.tn.nic.in/" target="_blank">Census 2011</a> and covers an area of
	 '.$statedata['title'].'&nbsp;&nbsp; Chennai (formerly known as Madras) is the State Headquarters.&nbsp; The administrative units of the State are:</div> </p>
	 <div id="abt_tn">
	 '.$statedata['field_tn_administrative_units_value'].'
	 <div class="clr"></div></div>
	 
	
	
	</div>';

}
return $strData;

}


function govtmpdata() {
global $base_url;

//drupal_set_title("<div class='titleview'>".t("Members  of Parliament from Tamil Nadu State")."</div>");
//drupal_set_title("Members  of Parliament from '.SITE_STATE.' State");
 
 $strOP = "<div class='govt_parli'>
 	<img src='http://www.tn.gov.in/sites/default/files/parliment.jpg'></div>" ;

$strOP .= "<div class='govt_parli_mps'>
	
	".l(t('Lok Sabha'),'government/loksaba')."&nbsp; &nbsp; &nbsp; | &nbsp; &nbsp; &nbsp;  ".l(t('Rajya Sabha'),'government/rajyasaba')."
	
</div>";


  $strOP .= "<div class='govt_parli_tn'>
 	<img src='http://www.tn.gov.in/sites/default/files/tn_build.jpg'></div>" ;

$strOP .= "<div class='govt_parli_mlas'>
	<p>		
		".l(t('MLA'),'government/mlas')."		
	</p>
</div>";





return $strOP;

}

function district_collectors (){

global $base_url,$language;
//$key = gettheme();
$module_path = drupal_get_path('module', 'government');
drupal_add_css(drupal_get_path('module', 'government') .'/government_citizen.css');

$head_title = t('District Collectors');
drupal_set_title($head_title);
   
    //IAS ID is 42 chk contact categroy table
$output = "<a name='top'></a><div>";	
    my_db_change(1);
$sql = "select dt_name,dt_cd from district_mst order by dt_name ASC";
$res=db_query($sql);
my_db_change(0);
  $output.="<div style='float:left;width:100%;margin-bottom:20px;'>";
       foreach($res as $dd_data) {   
      
       $output.="<div class='coll_menu'><a href='#".$dd_data->dt_cd."' onclick='javascript:district_class(".$dd_data->dt_cd." );'>".ucfirst(t($dd_data->dt_name))."</a></div>";
      
       }
  
  my_db_change(1);
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
 ->entityCondition('bundle', 'contact_dir_form')
 ->propertyCondition('status',1)
 ->propertyCondition('language', $language->language, '=')
 ->fieldCondition('field_cont_destination','value','42','=')
 ->fieldOrderby('field_cont_dist','value','ASC');
 $result = $query->execute();
 
 if (isset($result['node'])) {
 $news_items_nids = array_keys($result['node']); 
 $news_items = entity_load('node', $news_items_nids);
 }
 my_db_change(0);
 foreach ($news_items as $col_data) {
// print_r($col_data); die;
   if(!empty($col_data->field_cont_dist['und']['0']['value'])) {
$disttitle = "<a href='javascript:void(0);' onClick='return tnportal_ext_window(\"$map_data->field_dist_url_value\");'>".ucfirst(t(consticy_District_name($col_data->field_cont_dist['und']['0']['value'])))."</a>";
}else{
$disttitle = ucfirst($col_data->field_cont_dist['und']['0']['value']);
}
$output .="<div>
<div class='topleft_cur'></div>
<div class='dist_name'>
   <div class='dist_title'><a name='".$col_data->field_cont_dist['und']['0']['value']."'>".ucfirst(t($disttitle))."</a></div>
   <div  class='dist_top_icon'>
  <a href='#top' title='click to go top' style='text-decoration:none;' border=0><img src='".$base_url."/".$module_path."/images/".$key."/top_icon.png' alt='Top'/></a>                                    </div>
 </div>
 <div class='topright_cur'></div>
</div>	 
 
   <div  class='dist_connent'>
<div class='dist_col_map'>	
<div class='col_name'>".t(saluation_name($col_data->field_cont_salutation['und']['0']['value']))." ".$col_data->title."</div>	
<div class='ashclr'>".ucfirst(desgination_name($col_data->field_cont_destination['und']['0']['value']))."</div>
<div class='ashclr'>".ucfirst(t(consticy_District_name($col_data->field_cont_dist['und']['0']['value'])))." - ".$col_data->field_cont_pincode['und']['0']['value']."</div>
<div class='clr'></div>
    </div>	
           <div class='dist_right_contact'>	
<div class='hght15'></div>	
<div> ".t('Phone')." : ".$col_data->field_cont_phone1['und']['0']['value']."-".$col_data->field_cont_phone['und']['0']['value'].",".$col_data->field_cont_phone2['und'][0]['value']." ".$col_data->field_cont_landline['und']['0']['value']."</div> <div> ".t('Fax')." : ".$col_data->field_cont_cfax['und']['0']['value']."-".$col_data->field_cont_fax['und']['0']['value']."</div>
<div> ".t('E-Mail')." : <a href='mailto:".$col_data->field_cont_email['und']['0']['value']."'>".$col_data->field_cont_email['und']['0']['value']."</a></div>
            <div class='clr'></div>
										  </div>					  
				
				
			           </div>
					   <div class='bot_left_cur'></div>
				          <div class='bot_middle_line'></div>
				     <div class='bot_right_cur'></div>
					   
			<div ></div><div class='clr'></div>";
				
		}
		$output .= "<div class='clr'></div></div>";
 return $output;
}